// 角色管理模块的接口

// 导入请求函数
import request from "@/utils/request";
// 导入全部角色的返回值类型
import type { AllRoleResponseData, RoleData, MenuResponseData } from "./type";

//枚举API地址
enum API {
    // 获取全部的职位接口
    ALLROLE_URL = '/admin/acl/role/',
    // 新增职位的地址
    ADDROLE_URL = '/admin/acl/role/save',
    // 更新职位的地址
    UPDATEROLE_URL = '/admin/acl/role/update',
    // 获取全部菜单与按钮的数据
    ALLPERMISSION_URL = '/admin/acl/permission/toAssign/',
    // 给职位分配权限
    SETPERMISION_URL = '/admin/acl/permission/doAssign/?',
    // 删除已有的职位
    REMOVEROLE_URL = '/admin/acl/role/remove/',
}
// 获取全部职位的信息
export const reqAllRole = (pageNo: number, pageSize: number, keywords: string) => request.get<any, AllRoleResponseData>(API.ALLROLE_URL + `${pageNo}/${pageSize}/?roleName=${keywords}`)
// 新增或添加职位
export const reqAddOrUpdata = (data: RoleData) => {
    if (data.id) {
        return request.put<any, any>(API.UPDATEROLE_URL, data)
    } else {
        return request.post<any, any>(API.ADDROLE_URL, data);
    }
}
// 获取全部菜单与按钮权限数据
export const reqAllPermission = (roleId: number) => request.get<any, MenuResponseData>(API.ALLPERMISSION_URL + roleId)
// 给对应的职位下发权限
export const reqSetPermission = (roleId: number, permissionId: number[]) => request.post(API.SETPERMISION_URL + `roleId=${roleId}&permissionId=${permissionId}`);
// 删除职位的请求
export const reqRemoveRole = (roleId: number) => request.delete<any, any>(API.REMOVEROLE_URL + roleId)